﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using EnterpriseFund.Common;

namespace EnterpriseFund.Controllers
{
    public class YearTransferController:AdminBaseController
    {
        //
        // GET: /YearTransfer/

        public ActionResult Index()
        {
            BLL.Common CommonBLL = new BLL.Common();
            DataSet ds = CommonBLL.GetYear();
            List<int> yearList = new List<int>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                yearList.Add(int.Parse(ds.Tables[0].Rows[i]["FYear"].ToString()));
            }

            ViewData["lastYear"] = yearList.Max();
            return View("Index");
        }

        public ActionResult YearTransfers()
        {
            string year = Fetch.Post("hislastYear");
            BLL.SupportPolicy supportPolicy = new BLL.SupportPolicy();
            List<Model.SupportPolicy> sl = supportPolicy.GetModelList("");
            
            foreach (Model.SupportPolicy s in sl)
            {
                s.FYear = int.Parse(year) + 1;
            }
            try
            {
                BLL.Common commonBLL = new BLL.Common();
                if (Fetch.Post("hidtype") != "")
                {
                    if (Fetch.Post("hidtype") == "Transfer")
                    {
                        commonBLL.YearTransfer(year, sl);
                        ViewData["jsAlert"] = "结转成功";
                    }
                    else
                    {
                        commonBLL.YearTurnChange(decimal.Parse(year));
                        ViewData["jsAlert"] = "反结转成功";
                    }
                }
                else
                {
                    ViewData["jsAlert"] = "异常";
                }
        
            }
            catch(Exception ex)
            {
                ViewData["jsAlert"] = ex.Message;
            }
            return Index();
        }

    }
}
